import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';
import { deptSimple, userSimple } from '/@/api/backs/salary/salary';
import moment from 'moment';

export const columns: BasicColumn[] = [
  {
    title: '员工姓名',
    dataIndex: 'userName',
  },
  {
    title: '部门名称',
    dataIndex: 'deptName',
    customRender: ({ record }) => {
      if (record.deptName) {
        return record.deptName;
      } else {
        return '--';
      }
    },
  },
  {
    title: '项目名称',
    dataIndex: 'projectName',
    customRender: ({ record }) => {
      if (record.projectName) {
        return record.projectName;
      } else {
        return '--';
      }
    },
  },
  {
    title: '基础工资',
    dataIndex: 'baseSalary',
  },
  {
    title: '技术提成',
    dataIndex: 'technicalBonus',
  },
  {
    title: '奖金提成',
    dataIndex: 'rewardBonus',
  },
  {
    title: '法定扣款',
    dataIndex: 'statutoryDeduction',
  },
  {
    title: '加班工资',
    dataIndex: 'overtimeSalary',
  },
  {
    title: '扣款明细',
    dataIndex: 'deductionDetails',
  },
  {
    title: '考勤天数',
    dataIndex: 'attendanceDays',
  },
  {
    title: '结算日期',
    dataIndex: 'settlementDate',
    customRender: ({ record }) => {
      const time = record.settlementDate;
      return time ? moment(time).format('YYYY-MM-DD') : '-';
    },
  },
];

export const searchFormSchema: FormSchema[] = [
  {
    field: 'userId',
    label: '员工',
    component: 'ApiSelect',
    colProps: { span: 8 },
    componentProps: {
      api: userSimple,
      labelField: 'nickname',
      valueField: 'id',
      placeholder: '请选择员工',
    },
  },
  {
    field: 'deptIds',
    label: '部门',
    colProps: { span: 8 },
    component: 'ApiTreeSelect',
    componentProps: {
      placeholder: '请选择部门',
      api: deptSimple,
      labelField: 'name',
      valueField: 'id',
      dropdownStyle: { maxHeight: '400px', overflow: 'auto' },
      replaceFields: {
        children: 'children',
        title: 'name',
        key: 'id',
        value: 'id',
      },
    },
  },
];

export const formSchema: FormSchema[] = [
  {
    field: 'userIds',
    label: '员工',
    required: ({ values }) => (values.deptIds && values.deptIds.length ? false : true),
    component: 'ApiSelect',
    componentProps: {
      api: userSimple,
      labelField: 'nickname',
      valueField: 'id',
      placeholder: '请选择员工',
      mode: 'multiple',
      showSearch: true,
      filterOption: (input, option) => {
        return option.label.toLowerCase().indexOf(input.toLowerCase()) >= 0;
      },
    },
    dynamicDisabled: ({ values }) => (values.deptIds && values.deptIds.length ? true : false),
  },
  // {
  //   field: 'projectId',
  //   label: '项目',
  //   component: 'ApiSelect',
  //   colProps: { span: 8 },
  //   componentProps: {
  //     api: deptSimple,
  //     labelField: 'label',
  //     valueField: 'value',
  //     placeholder: '请选择项目',
  //     mode: 'multiple',
  //     params: {
  //       dictType: 'bpm_model_category',
  //     }
  //   },
  // },
  {
    field: 'deptIds',
    label: '指定部门',
    required: ({ values }) => (values.userIds && values.userIds.length ? false : true),
    component: 'ApiTreeSelect',
    componentProps: {
      placeholder: '请选择指定部门',
      api: deptSimple,
      labelField: 'name',
      valueField: 'id',
      treeCheckable: true,
      dropdownStyle: { maxHeight: '400px', overflow: 'auto' },
      replaceFields: {
        children: 'children',
        title: 'name',
        key: 'id',
        value: 'id',
      },
    },
    dynamicDisabled: ({ values }) => (values.userIds && values.userIds.length ? true : false),
  },
  {
    field: 'attendanceMonth',
    label: '考勤月份',
    required: true,
    component: 'MonthPicker',
    componentProps: {
      placeholder: '请选择考勤月份',
      valueFormat: 'yyyy-MM',
    },
  },
  // {
  //   field: 'restDays',
  //   label: '休息天数',
  //   component: 'InputNumber',
  //   componentProps: {
  //     placeholder: '请输入休息天数',
  //   },
  // },
  {
    field: 'reType',
    label: '统计类型',
    component: 'Select',
    componentProps: {
      options: [
        {
          label: '项目统计',
          value: 1,
        },
        {
          label: '部门统计',
          value: 0,
        },
      ],
    },
    required: true,
  },
];
